<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>
    <include file="Public/sidebar"/>
        <div class="main-content">
            <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
                <include file="Public/breadcrumbs"/>
                <!-- /section:basics/content.breadcrumbs -->
                    <div class="page-content">
                        <include file="Public/set"/>

                        <!-- /section:settings.box -->
                        <div class="row">
                            <div class="col-xs-12 "  style="padding: 35px;" >
                                <div class="form-in ">
                                    <form action="" method="post" enctype="multipart/form-data">
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span class="cngs">物料号</span>
                                                </div>
                                                <input type="text" name="item_no" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>描述</span>
                                                </div>
                                                <input type="text" name="item_desc" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>种类</span>
                                                </div>
                                                <input type="text" name="item_category" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>最小订购</span>
                                                </div>
                                                <input type="text" name="min_order" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>售价</span>
                                                </div>
                                                <input type="text" name="unit_price" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>安全库存</span>
                                                </div>
                                                <input type="text" name="safe_qty" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>采购价格</span>
                                                </div>
                                                <input type="text" name="go_price" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>item_type</span>
                                                </div>
                                                <input type="text" name="item_type" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>供应商编码</span>
                                                </div>
                                                <input type="text" name="supplier_name" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>单位</span>
                                                </div>
                                                <select class="ck" load="" name="units" class="form-control">
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <span>图像</span>
                                                </div>
                                                <input type="file" name="image" class="form-control">
                                            </div>
                                        </div>
                                        <!-- <input type="text" name="disable_flag"> -->                        
                                        <div class="col-xs-12 text-right">
                                            <button class="btn btn-success">添加</button>    
                                        </div>
                                    </form>
                                </div>
                            </div><!-- /.col -->
                        </div><!-- /.row -->
                    </div><!-- /.page-content -->
                </div>
            </div><!-- /.main-content -->
        <include file="Public/footer"/>

        </div><!-- /.main-container -->

        <include file="Public/footerjs"/>
    <!-- inline scripts related to this page -->

<div class="modal fade ck-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
          <h3 class="modal-title">
              企业编号查询
          </h3>
      </div>
      <div class="modal-body">
        <div class="col-xs-3 col-xs-offset-4">
            <input type="text" name="vendor-name" class="form-control vendor-input-code" placeholder="供应商编号">
        </div>
        <div class="col-xs-3">
            <input type="text" name="vendor-code" class="form-control vendor-input-name" placeholder="供应商名称">
        </div>
        <div class="col-xs-1">
            <button class="btn btn-primary btn-sm vendor-search">
                <span class="glyphicon glyphicon-search"></span> 搜索
            </button>
        </div>
        <div class="row" >
            <table class="table table-bordered  vendor-table">
                <tr >
                    <th class="text-center">供应商编号</th>
                    <th class="text-center">供应商名称</th>
                    <th class="text-center">联系人</th>
                    <th class="text-center">联系电话</th>
                    <th class="text-center">联系地址</th>
                    <th class="text-center">操作</th>
                </tr>
                <volist name="info" id="vo">
                    <tr class="vendor_{$vo['vendor_id']}">
                        <td>{$vo['vendor_code']}</td>
                        <td>{$vo['vendor_name']}</td>
                        <td>{$vo['vendor_contacts']}</td>
                        <td>{$vo['contacts_phone']}</td>
                        <td>{$vo['vendor_address']}</td>
                        <td class="text-center">
                            <span onclick='showinfo({$vo['vendor_id']})'><span class='glyphicon glyphicon-zoom-in text-info' ></span> 查看详细信息</span> 
                            |
                            <span onclick='deleteinfo({$vo['vendor_id']})'><span class='glyphicon glyphicon-trash text-danger'></span> 删除</span>
                        </td>
                    </tr>
                </volist> 
            </table>
        </div>
            <div class="row text-center">
                <button class="btn btn-defalut" onclick="load_desc()"><<</button>
                <button class="btn btn-defalut" onclick="load_add()">>></button>
            </div>
      </div>
      <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>

    </div>
  </div>
</div>


    </body>
</html>

<script type="text/javascript">
var page=0;
    $(".ck").click(function(){
        $.ajax({
            url:'{:U('Unitsofmeasure/achieve')}',
            success:function(data){
                var load=$(".ck").attr("load");
                if(load){
                }else{
                    for(x in data){
                        var tion=$("<option value='"+data[x].unitname+"'>"+data[x].unitname+"</option>");
                        tion.appendTo(".ck");
                    }
                    $(".ck").attr("load","load");
                }
            }
        })
    })
    $("input[name=supplier_name]").click(function(){
        $(".ck-lg").modal('show');
    })
    $("input[name=item_no]").keyup(function(){
        var name=$(this).val();
        $.ajax({
            url:'{:U('Itemno/is_itemno')}?name='+name,
            success:function(data){
                if(data.status){
                    $(".cngs").text("已存在");
                    $(".cngs").css("color","#F00");
                }else{
                    $(".cngs").text("物料号");
                    $(".cngs").css("color","#000");
                
                }
            }
        
        })
    })
    load_add();
    function load_add(){
        page=page+1;
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/page')}?page='+page,
            success:function(data){
                table(data);
            }
        })
    }
    function load_desc(){
        page=page-1;
        if(page<=0){
            page=1;
        }
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/page')}?page='+page,
            success:function(data){
                table(data);
            }
        })
    }
    $(".vendor-search").click(function(){
        var code=$(".vendor-input-code").val();
        var name=$(".vendor-input-name").val();
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/vendor_search')}?name='+name+'&code='+code,
            success:function(data){
                table(data);
            }
        })
    })
    function table(data){
        $(".vendor-table").html("");
        var trh=$("<tr></tr>");
        var th_0=$("<th class='text-center'>供应商编号</th>");
        var th_1=$("<th class='text-center'>供应商名称</th>");
        var th_2=$("<th class='text-center'>联系人</th>");
        var th_3=$("<th class='text-center'>联系电话</th>");
        var th_4=$("<th class='text-center'>联系地址</th>");
        var th_5=$("<th class='text-center'>操作</th>");
        th_0.appendTo(trh);
        th_1.appendTo(trh);
        th_2.appendTo(trh);
        th_3.appendTo(trh);
        th_4.appendTo(trh);
        th_5.appendTo(trh);
        trh.appendTo(".vendor-table");
        for(x in data){
            var tr=$("<tr class='vendor_"+data[x].vendor_id+"'></tr>");
            var td_0=$("<td>"+data[x].vendor_code+"</td>");
            var td_1=$("<td>"+data[x].vendor_name+"</td>");
            var td_2=$("<td>"+data[x].vendor_contacts+"</td>");
            var td_3=$("<td>"+data[x].contacts_phone+"</td>");
            var td_5=$("<td>"+data[x].vendor_address+"</td>");
            
            var td_4=$("<td class='text-center'><span onclick=add_one('"+data[x].vendor_code+"') class='text-success glyphicon glyphicon-plus'></span></td>");
            td_0.appendTo(tr);
            td_1.appendTo(tr);
            td_2.appendTo(tr);
            td_3.appendTo(tr);
            td_5.appendTo(tr);

            td_4.appendTo(tr);
            tr.appendTo(".vendor-table")
        }
    }
    function add_one(data){
        if (data) {
            $("input[name=supplier_name]").val(data);
            $(".ck-lg").modal('hide');
        }
    }

</script>